<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta name="screen-orientation" content="portrait">
    <meta name="x5-orientation" content="portrait">
    <title>聚财通</title>
    <link rel="stylesheet" href="../../styles/h5/reset.min.css"/>
    <link rel="stylesheet" href="../../styles/h5/errortankuang.css"/>
    <!--以上为公共css样式-->
    <link rel="stylesheet" href="../../styles/h5/fund.css"/>
    <link rel="stylesheet" href="../../styles/h5/dropload.css"/>

    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery-1.9.1.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/jquery.modal.js"></script>
    <script charset="utf-8" type="text/javascript" src="../../scripts/h5/echarts.min(jj).js"></script>
    <!--以上为公共js文件-->
</head>
<body>
<div class="zz-openAccount-jj">
    <a class="zz-billIcon-jj" href="javascript:;"></a>
    <p class="zz-openAccountZuo-jj">昨日收益(元)</p>
    <p class="zz-openAccountShou-jj" id="zz-openAccountShou-jj">--</p>
    <p class="zz-openAccountAll-jj">总资产(元)<span class="zz-eye-jj" amtDisStatus="0"></span></p>
    <p class="zz-openAccountQian-jj" id="zz-openAccountQian-jj">--</p>
</div>
<div class="zz-allProfit-jj">
    <div class="zz-profit-jj fl">
        <a href="javascript:;" class="zz-profitleiji-jj">
            <span class="zz-profitSpan-jj">累计收益(元)</span>
            <span class="totalIncome" id="totalIncome">--</span>
        </a>
    </div>
    <div class="zz-profit-jj fr">
        <a href="javascript:;" class="zz-profitwanfen-jj">
            <span class="zz-profitSpan-jj">万份收益(元)</span>
            <span class="unitAccrua" id="unitAccrua">--</span>
        </a>
    </div>
    <div class="zz-profitshuxian-jj"></div>
</div>
<div class="zz-sevenshouyi-jj">
    七日年化收益率(%)：<span class="zz-sevenDaySpan-jj" id="zz-sevenDaySpan-jj">--</span><span class="zz-up-jj" id="zz-up-jj"
                                                                                     style="display: none"></span>
</div>
<div class="zz-EChartsList-jj">
    <div class="zz-myChart-jj" id="myChart"></div>
    <div class="zz-dayList-jj">
        <span class="zz-dayStart-jj"></span>
        <span class="zz-dayEnd-jj"></span>
    </div>
</div>
<div class="zz-fundManagement-jj margin-top16">
    <div class="zz-fundTop-jj" id="zz-fundTop-jj">
        <span class="zz-fundIcon-jj"></span>资金管理
        <span class="zz-jiantouUp-jj"></span>
    </div>
    <div class="zz-fundContent-jj" style="display: none">
        <span class="zz-fundAuto-jj">结算款自动转入</span>
        <span class="zz-settleAuto-jj">从结算款自动把资金转入到聚财通</span>
        <!--<div class="zz-choiceOpen-jj"></div>-->
        <div class="zz-switch-box">
            <label class="label" isRefund="0"></label>
        </div>
    </div>
</div>
<input class="footer zz-footTop" type="button" value="取出">
<div class="zz-footerIcon-jj">
    <span class="zz-umfIcon-jj"></span>
</div>
</body>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/utils.js"></script>
<script charset="utf-8" type="text/javascript" src="../../scripts/h5/dropload.min.js"></script>
<!--<script charset="utf-8" type="text/javascript" src="../../scripts/h5/index.js"></script>-->
<script charset="utf-8" type="text/javascript">
    utils.countRem();
    $(window).resize(function () {
        eChart();
        utils.countRem();
    });

    var $jiantouUp = $(".zz-jiantouUp-jj");
    var $openAccountQian = $("#zz-openAccountQian-jj");
    var $eye = $(".zz-eye-jj");
    var flag = true;
    var flagEye = true;
    var openAccountQian = "";
    var data = "";
    var dataX = [];
    var dataY = [];
    var minAnnual7D = "";
    var maxAnnual7D = "";
    var amtDisStatus = "";
    var autoRollInStatus = "";
    var title = "";
    var content = "";
    var flag2 = true;
    var timer ="";
    var title1 = "结算款自动买入即将开启";
    var content1 = "因结算款自动买入功能与自动结算互斥，开启后将为您自动关闭自动结算功能，如继续请点击下方确定，如取消则点击下方取消按钮";
    var title2 = "结算款自动买入即将关闭";
    var content2 = "因结算款自动买入功能与自动结算互斥，关闭后将为您自动开通自动结算功能，如继续请点击下方确定，如取消则点击下方取消按钮";
    //初始化页面数据
    ajaxInit();
    function ajaxInit(callback,me){
	    $.ajax({
	        url: utils.ajaxUrl()+"h5/fund/opendAccount/initOpendAccount",
	        async: false,
	        type: 'get',
	        success: function (res) {
	            var res = JSON.parse(res);
	            console.log(res);
	            if (res && res.retCode == '0000') {
	                if(res.lastdayProfit>0){
                        $("#zz-openAccountShou-jj").html(utils.comma(res.lastdayProfit));
                    }
                    if(res.totalVol>0){
                        openAccountQian = utils.comma(res.totalVol);
                    }else{
                        openAccountQian = "--";
                    }
                    if(res.totalIncome>0){
                        $("#totalIncome").html(utils.comma(res.totalIncome));
                    }
                    if(res.unitAccrua>0){
                        $("#unitAccrua").html(res.unitAccrua);
                    }
                    if(res.annual7D>0){
                        $("#zz-sevenDaySpan-jj").html(res.annual7D);
                    }
	                if (res.isUp == 1) {
	                    $("#zz-up-jj").show()
	                }
	                amtDisStatus = res.amtDisStatus;
	                if (amtDisStatus == 0) {
	                    $eye.addClass("zz-closeEye-jj");
	                    $openAccountQian.html("****");
	                    flagEye = false;
	                } else {
	                    $eye.removeClass("zz-closeEye-jj");
	                    $openAccountQian.html(openAccountQian);
	                    flagEye = true;
	                }
	                
	                data = res.annual7DList;
	                if(data && data.length>0){
		                $(".zz-dayStart-jj").html((data[0].oppositeDate).slice(5, 10));
		                $(".zz-dayEnd-jj").html((data[data.length - 1].oppositeDate).slice(5, 10));
		                
		                maxAnnual7D = parseFloat(utils.calculation(parseFloat(res.maxAnnual7D),0.02,"+")).toFixed(2);//最大七日 y轴最大值
		                /* maxAnnual7D = utils.calculation(parseFloat(res.maxAnnual7D),0.2,"+").toString();//最大七日
	                    maxAnnual7D = maxAnnual7D.slice(0,1)+maxAnnual7D.slice(1,3);
	                    var arr = maxAnnual7D.toString().split(".");
	                    if(arr[1]%2 !=0){
	                        maxAnnual7D = utils.calculation(parseFloat(maxAnnual7D),"0.1","+");
	                    } */
	
						minAnnual7D = parseFloat(utils.calculation(parseFloat(res.minAnnual7D),0.02,"-")).toFixed(2);//最小七日 y轴最小值
	                    /* minAnnual7D = utils.calculation(parseFloat(res.minAnnual7D),0.2,"-").toString();//最小七日
	                    minAnnual7D = minAnnual7D.slice(0,1)+minAnnual7D.slice(1,3);
	                    var arr2 = minAnnual7D.toString().split(".");
	                    if(arr2[1]%2 !=0){
	                        minAnnual7D = utils.calculation(parseFloat(minAnnual7D),"0.1","+");
	                    } */
	                    
		                bindEchartData();
		                eChart();
					}
					
	                autoRollInStatus = res.autoRollInStatus;
	                if(autoRollInStatus ==0){
	                    $(".label").addClass("l bg");
	                    flag2 = false;
	                    title = title1;
	                    content = content1;
	                }else{
	                    $(".label").removeClass("l bg");
	                    flag2 = true;
	                    title = title2;
	                    content = content2;
	                }
	                if(callback !=undefined){
	                    callback(me);
	                }
	            } else {
	                utils.error("sx.png", "啊哦，数据异常");
	            }
	        },
	        error: function () {
	            utils.error("wlyc.png", "啊哦，连接不到网络呢");
	        }
	    });
    }
    function loadUp(me){
        // 为了测试，延迟1秒加载
        clearTimeout(timer);
        timer = setTimeout(function () {
            me.resetload();
            me.unlock();
        }, 100);
    }

    $(function () {
        // dropload
        $('body').dropload({
            scrollArea: window,
            domUp: {
                domClass: 'dropload-up',
                domRefresh: '<div class="dropload-refresh">↓下拉刷新</div>',
                domUpdate: '<div class="dropload-update">↑释放更新</div>',
                domLoad: '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
            },
            // 下拉刷新
            loadUpFn: function (me) {
                ajaxInit(loadUp,me);
            },
            distance:50,
            threshold:3
        });
    });

    $eye.click(function () {
        var that = $(this);
        if (flagEye) {
            amtDisStatus = 0;
            that.addClass("zz-closeEye-jj");
            $openAccountQian.html("****")
        } else {
            amtDisStatus = 1;
            that.removeClass("zz-closeEye-jj");
            $openAccountQian.html(openAccountQian)
        }
        flagEye = !flagEye;

        $.ajax({
            url: utils.ajaxUrl()+"h5/fund/opendAccount/setAmtDisStatus",
            data: {
                amtDisStatus: amtDisStatus
            },
            async: false,
            type: 'get',
            success: function (res) {
                var res = JSON.parse(res);
                console.log(res);
                if (res && res.retCode == '0000') {

                } else {
                    utils.error("sx.png", "啊哦，数据异常");
                }
            },
            error: function () {
                utils.error("wlyc.png", "啊哦，连接不到网络呢");
            }
        });
    });

    //绑定图表数据
    function bindEchartData() {
        dataX = [];
        dataY = [];
        for (var i = 0; i < data.length; i++) {
            var curData = data[i];
            dataX.push(curData.oppositeDate);
            dataY.push(curData.annual7D);
        }
    }

    function eChart() {

        var myChart = echarts.init(document.getElementById('myChart'));
        var option = {
            backgroundColor: "#fff",
            tooltip: {
                show: true,
                trigger: 'axis',
                //axisPointer:{type:"none",},
                backgroundColor: "#508cee",
                borderWidth: "0",
                borderRadius: "0",
                formatter: function (params) {
                    return params[0].axisValue + '<br>' + params[0].data + "%";
                },
                axisPointer: {
                    axis: "auto",
                    type: "line",
                    lineStyle: {
                        color: "#a7c5f7"
                    }
                },
                textStyle: {
                    color: "#fff",
                    fontSize: 14
                }
            },
            grid: {
                left: '15',
                right: '15',
                bottom: '12%',
                containLabel: true,
                //width:220,
                height: 160
            },
            toolbox: {
                show: true,
                feature: {
                    dataZoom: {
                        yAxisIndex: 'none'
                    },
                    dataView: {readOnly: false},
                    magicType: {type: ['line', 'ar']},
                    restore: {},
                    saveAsImage: {}
                }
            },
            xAxis: {
                show: false,
                type: 'category',
                boundaryGap: false,
                //min:"dataMin",
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: "#d5d5d5"
                    }

                },
                axisTick: {
                    show: false
                },
                data: dataX
            },
            yAxis: {
                type: 'value',
                min: minAnnual7D,
                max: maxAnnual7D,
                //interval:"1",
                //splitNumber: "4",
                axisLine: {
                    show: false,
                    lineStyle: {
                        color: "#d5d5d5"
                    }
                },
                axisTick: {
                    show: false
                },
                z: 10,
                axisLabel: {
                    inside: true,
                    //formatter: "{value}.0000%",
                    formatter: function (s) {
                        //console.log(s);
                        var a = s.toString().split(".");
                        if (a[1]) {
                            if(a[1].length ==1){
                                a = a[0] + "." + a[1] + "0";
                            }else{
                                a = a[0] + "." + a[1];
                            }
                        } else {
                            a = a + ".00"
                        }
                        return a+ "%";
                    },
                    fontSize: 12
                },
                splitLine: {
                    lineStyle: {
                        color: "#f6f6f6"
                    }
                }
            },
            series: [
                {
                    name: '',
                    type: 'line',
                    data: dataY,
                    itemStyle: {
                        normal: {
                            color: "#508cee",
                            //borderWidth: "0",
                            lineStyle: {
                                color: "#508cee",
                                width: 1,
                                type: "solid"
                            },
                            areaStyle: {color: "#f3f8fe"},
                            label: {
                                //show:"false"
                            }
                        }
                    },
                    markLine: {
                        silent: true,
                        lineStyle: {
                            normal: {
                                color: "#333"
                            }
                        }
                    },
                    symbol: 'emptyCircle',
                    symbolSize: 6,
                    showSymbol: false,
                    hoverAnimation: false,
                    z: 10
                }
            ]
        };
        // 为echarts对象加载数据
        myChart.setOption(option);
    }

    $("#zz-fundTop-jj").click(function () {
        $(".zz-fundContent-jj").slideToggle();
        if (flag) {
            $jiantouUp.addClass("zz-jiantouDown-jj");
        } else {
            $jiantouUp.removeClass("zz-jiantouDown-jj");
        }
        flag = !flag;
    });

    $(".label").click(function () {
        var $this = $(this);
        new $.modal({
            title: title,//弹框title
            content: content,//弹框内容
            confirm: "",//确认按钮里面内容
            isshowclosebtn: true,//是否显示取消按钮
            showcontent: false,//false为弹出框组件二，true为弹出框组件一
            closecallback: function () {

            },//点击关闭时触发事件
            surecallback: function () {
                //点击确定时触发事件
                if (flag2) {
                    $this.addClass("l bg");
                    autoRollInStatus = 0;
                    title = title1;
                    content = content1;
                } else {
                    autoRollInStatus = 1;
                    $this.removeClass("l bg");
                    title = title2;
                    content = content2;
                }
                flag2 = !flag2;
                $.ajax({
                    url: utils.ajaxUrl()+"h5/openFundController/autoPurchase",
                    data: {
                        state: autoRollInStatus
                    },
                    async: false,
                    type: 'get',
                    success: function (res) {
                        var res = JSON.parse(res);
                        console.log(res);
                        if (res && res.retCode == '0000') {

                        } else {
                            utils.error("sx.png", "啊哦，数据异常");
                        }
                    },
                    error: function () {
                        utils.error("wlyc.png", "啊哦，连接不到网络呢");
                    }
                });
            }
        }).show();
    });

    $(".zz-billIcon-jj").click(function () {
        window.location.href = "../../html/h5/fundSearchOrder.html";
    });
    $(".zz-openAccountShou-jj").click(function () {
        window.location.href = "../../html/h5/fundSearchProfit.html";
    });
    $(".zz-profitleiji-jj").click(function () {
        window.location.href = "../../html/h5/fundSearchProfit.html";
    });
    $(".zz-profitwanfen-jj").click(function () {
        window.location.href = "../../html/h5/fundProfit.html?choiceP=oppositeDate";
    });
    $(".zz-sevenDaySpan-jj").click(function () {
        window.location.href = "../../html/h5/fundProfit.html";
    });
    $(".footer").click(function () {
        window.location.href = "../../html/h5/fundRollOut.html";
    })
</script>
</html>